import java.util.ArrayList;
import java.util.Iterator;

    public class Solution {
        public static void main(String[] args) {
            ArrayList<String> list = new ArrayList<>();
            list.add("hello");
            list.add("word");
            list.add("HELLO");
            list.add("WORD");

            Iterator<String> iterator = list.iterator();
            System.out.println("使用迭代器打印所有元素:");
            while (iterator.hasNext()) {
                System.out.println(iterator.next());
            }

            list.remove("word");
            System.out.println("删除 'word' 后的所有元素:");
            System.out.println(list);

            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).equals("hello")) {
                    list.set(i, "nihao");
                }
            }
            System.out.println("将 'hello' 替换为 'nihao' 后的所有元素:");
            System.out.println(list);
        }
    }
